﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;

namespace BSCMFF.Web.Pages.Reporting
{
    public partial class EvaluationCharts : BSCMFF.Core.MultiLanguagePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadSurveyData(5);
        }

        private void LoadSurveyData(int formID)
        {
            BSCEntities context = new BSCEntities();

            var results = (from r in context.Survey_Results.Include("Survey_Answer.Survey_Question.Survey_Form")
                           where r.Survey_Answer.Survey_Question.Survey_Form.ID == formID
                           group r by new { r.Survey_Answer.Question_FK, r.Survey_Answer.ID } into q
                           select new { count = q.Count(), answers = q.Key.ID, quest = q.Key.Question_FK }).ToList();

            List<string> questionsName = (from q in context.Survey_Question.Include("Survey_Form")
                                 where q.Survey_Form.ID == formID
                                 select q.Question).ToList();

            foreach (string qn in questionsName)
            {
                RadChart1.PlotArea.XAxis.AddItem(qn);
            }

            RadChart1.DataSource = results;
            RadChart1.DataGroupColumn = "Question_FK";
            RadChart1.DataBind();
            //RadChart1.data
        }

        protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {

        }
    }
}